package com.tdg.qywx.core;

import com.tdg.qywx.controller.OperateController;
import com.tdg.qywx.core.enums.TDGResponseCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    private static final Logger _logger = LoggerFactory.getLogger(OperateController.class);

    // 捕获所有运行时异常
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public TDGResponse handleRuntimeException(Exception e) {
        _logger.error("全局异常 ==> RuntimeException：", e);
        return TDGResponse.fail(TDGResponseCode.ERROR, e.getCause().getMessage());
    }
}
